package com.von.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.von.commonutils.R;
import com.von.eduservice.entity.EduCourse;
import com.von.eduservice.entity.EduTeacher;
import com.von.eduservice.service.EduCourseService;
import com.von.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Vonzhe
 * @create 2020/5/19 15:13
 **/
@RestController
@CrossOrigin
@RequestMapping("/eduservice/indexfront")
public class IndexfrontController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    @GetMapping("index")
    public R index(){
        //查询前8条热门课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> listC = courseService.list(wrapper);
        //前8位名师
        QueryWrapper<EduTeacher> wrapperT = new QueryWrapper<>();
        wrapperT.orderByDesc("id");
        wrapperT.last("limit 4");
        List<EduTeacher> listT = teacherService.list(wrapperT);

        return R.ok().data("courseList",listC).data("teacherList",listT);
    }
}
